shell命令传递参数完整范例(cronhub调度系统daemon安装脚本)

您所在的位置:网站首页 shell脚本 入参 shell命令传递参数完整范例(cronhub调度系统daemon安装脚本)

shell命令传递参数完整范例(cronhub调度系统daemon安装脚本)

2023-04-28 15:39| 来源: 网络整理| 查看: 265

shell命令传递参数完整范例(cronhub调度系统daemon安装脚本) 原创

sharpstill 2014-01-28 23:15:19 博主文章分类:linux与shell ©著作权

文章标签 shell 调度系统 文章分类 运维

©著作权归作者所有:来自51CTO博客作者sharpstill的原创作品,请联系作者获取转载授权,否则将追究法律责任 #!/bin/bashfunction usage(){     echo "Usage Example: ./install_start.sh -d /opt/modules/daemon -s 2012 -i 192.168.0.1 -p 8080"     echo "-d  install directory path";     echo "-s  daemon boot start port";     echo "-i   cronhub center server's ip is used for download daemon's jar and  jdk and jsvc  and so on"     echo "-p  cronhub center server's port used for download daemon's jar and  jdk and jsvc  and so on"}if [ $# -ne 8 ];#如果参数没有8个,算上-s啥的,那么就从用户输入读入then    echo "please input the directory path that you want to install";    read install_path;    echo "please input the cronhub center server's ip..."    read center_server_ip;    echo "please input the cronhub center server's port..."    read center_server_port;    echo "please input the daemon boot start port..."    read daemon_port;#下面就是shell的多行注释的方法: /etc/init.d/cronhub_daemon/sbin/chkconfig --add cronhub_daemon#start daemonecho "adding to service done,now start daemon service..."chmod +x /etc/init.d/cronhub_daemon/sbin/service cronhub_daemon startecho "all done"#the final start cmd#$jsvc_target_bin -home $java_home -Xmx2000m -pidfile $install_path"/"$daemon_port".pid" -cp $daemon_jar_path com.baofeng.dispatchexecutor.boot.DaemonBoot -p $daemon_port【转载】shell的getopts范例getopts使用说明: 这里的option-string是一个字符串,它包含了getopts所应该考虑的所有单个选项字符。var是该选项应该被设置的变量的名字,通常而言,var是一个名为OPTION的变量。getopts对命令行中给出的选项进行解释的步骤如下。1.getopts检查所有的命令行参数,查找以-为字符开头的参数。2.当发现一个以-字符开头的参数时,它比较-之后紧接着的字符与给定的option-string中所有字符。3.如果发现该字符在option-string中有匹配,则把该选项字符赋予变量var;否则,var的值设置为?字符。4.重复步骤1~3,直到命令行中给出的所有选项都被检查完。5.当选项解析完成后,getopts返回一个非0的退出码--这使得getopts很容易地被使用在循环中。另外,当getopts结束时,它被变量OPTION的值设置为最后一个参数的下标。getopts的另一个特点是它能够指出哪些选项要求带参数,这是通过在选项后面附加一个冒号(:)字符来实现的。在这种情况下,解析一个选项后,附带的参数就会设置为变量OPTARG的值。最近在学shell,刚看到getopts,搜到这个贴。上面getopts的用法来自<精通shell编程>这本书。对着书看上面的脚本。很容易看懂#!/sbin/sh# ftpuseraddusage(){echo "Usage: `basename $0` [-w] [-m maxrate] username password"exit 1}WRITABLE="no" # can't uploadMAXRATE="64000" # default max rate is 64KbOPT="no"while getopts :wm: OPTIONdo  case $OPTION in  w) WRITABLE="yes"    OPT="yes"    ;;  m) MAXRATE=$OPTARG    OPT="yes"    ;;  \?) usage    ;;  esacdoneshift `expr $OPTIND - 1`if [ $# -ne 2 ]then  usagefiUSERNAME=$1PASSWORD=$2useradd -d /dev/null -g ftp -s /bin/false $USERNAMEif [ $? -eq 0 ]then  setpasswd.exp $USERNAME $PASSWORD > /dev/null  echo "anon_world_readable_only=NO" > /etc/vsftpd/$USERNAME  echo "anon_max_rate=$MAXRATE" >> /etc/vsftpd/$USERNAME  if [ "$WRITABLE" = "yes" ]  then    echo "write_enable=YES" >> /etc/vsftpd/$USERNAME    echo "anon_upload_enable=YES" >> /etc/vsftpd/$USERNAME    echo "anon_mkdir_write_enable=YES" >> /etc/vsftpd/$USERNAME    echo "anon_other_write_enable=YES" >> /etc/vsftpd/$USERNAME  fi  echo "$USERNAME" >> /etc/vsftpd.user_list

打赏 收藏 评论 分享 举报

上一篇:linux find出所有log文件,然后删除

下一篇:部署mongodb做replica set分布式



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3